<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link rel="shortcut icon" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/logo.png"/>
	<title>退款申请</title>
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.min.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/other/all.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/other/app.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.picker.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.poppicker.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/font/iconfont.css" rel="stylesheet" />

	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.min.js"></script>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.picker.js"></script>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.poppicker.js"></script>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/city.data.js" type="text/javascript" charset="utf-8"></script>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/city.data-3.js" type="text/javascript" charset="utf-8"></script>
</head>
<style type="text/css">
	.tukla{line-height: 20px;padding: 0 !important}
	.tukla span,#totalprice{color:#b4282d !important;}
	.mui-content,.refund-application{padding-bottom: 0}
	 .addevaluation{width: 100%}
	 .add_address div input{border:0;margin: 0;text-align: right;}
	 /*#form{margin-top: 10px;}*/
	 .tips{padding: 10px;line-height: 20px;}
</style>
<body>
	<div class="refund-application">
		<div class="mui-content">
		<form id="form">
		<div class="all_list clear">
			<h1><a href="/index/shop?id={{.info.gid}}">
				<span class="mui-icon iconfont fs-16">&#xe75f;</span> 
				{{if .info.gname}}{{.info.gname}}{{else}}{{$.system.name}}{{end}}
				</a>
			</h1>
			{{range .info.shopcar}}
				<div class="commodity_details">
					<div class="commodity">
						<a class="one goto" href="/mobile/column/product_content?id={{.pid}}">
							<div>
								<img src="{{.pathname}}">
								<div>
									<p>{{.title}}</p>
									<p>
										规格 : {{.number}}{{.spec}}/箱<br>
										型号 : {{.model}}<br>
									</p>
									<p class="bfd">￥ {{.price}}<span class="fr">
									{{if eq .status "3" "4"}}
									{{if eq .num .sendnum}}
									x{{.num}}
									{{else}}
									实发{{.sendnum}}/{{.num}}
									{{end}}
									{{else}}
									x{{.num}}
									{{end}}{{if eq .spec2 "1"}}件{{else}}箱{{end}}
									</span></p>
								</div>
							</div>
						</a>
					</div>
				</div>
				<div class="add_address">
					<div>
						<label>退换数量</label>
						<input type="tel" name="shopcar" value="{{if .rinfo}}{{.rnum}}{{else}}1{{end}}" placeholder="请输入您要退换的数量">
					</div>
				</div>
			</div>
			{{end}}
		</div>
		<p class="tips">Tips:退换数量以实际到货为准</p>

			<div class="add_address">
				{{ if eq .info.isre 1 }}
				<div id="showUserPicker2">
					<label>退款类别</label>
					<span class="fr mui-icon iconfont">&#xe6f7;</span>
					<span class="fr" id="userResult2">{{if .rinfo}}{{if .rinfo.type "0"}}退货{{else}}换货{{end}}{{else}}请选择{{end}}</span>
					<input type="hidden" name="type" id="type" value="{{.rinfo.type}}">
				</div>
				{{ else if eq .info.isre 2 }}
				<div>
					<label>退款类别</label>
					<span class="fr mui-icon iconfont">&#xe6f7;</span>
					<span class="fr">退货</span>
					<input type="hidden" name="type" id="type" value="0">
				</div>
				{{ else if eq .info.isre 3 }}
				<div>
					<label>退款类别</label>
					<span class="fr mui-icon iconfont">&#xe6f7;</span>
					<span class="fr">换货</span>
					<input type="hidden" name="type" id="type" value="1">
				</div>
				{{end}}
				<div id="showUserPicker1">
					<label>退款原因</label>
					<span class="fr mui-icon iconfont">&#xe6f7;</span>
					<span class="fr" id="userResult1">{{if .rinfo.wname}}{{.rinfo.wname}}{{else}}请选择{{end}}</span>
					<input type="hidden" name="why" id="why" value="{{.rinfo.why}}">
				</div>
				<input type="hidden" name="oid" value="{{.info.id}}" id="oid">
				<input type="hidden" name="rid" value="{{.rinfo.id}}">
			</div>
			<div class="addevaluation">
				<textarea id="reason2" placeholder="请填写退款说明" name="intr" id="intr">{{.rinfo.intr}}</textarea>
				<!-- <div>
					<img src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/images/index/jiuye.jpg">
				</div> -->
			</div>
		</form>
		<div class="tx-c tjevaluation">
			<button id="btn" class="btn">提交</button>
		</div>
	</div>
</body>
</html>
{{template "wechat/public/share.html" .}}
<script type="text/javascript">
	(function($, doc) {
		$.init();
		$.ready(function() {
			//普通示例
			var userPicker1 = new $.PopPicker();
			userPicker1.setData([{{range .why}}{
				text: '{{.name}}',value:{{.id}} 
			},{{end}}]);
			var showUserPickerButton1 = doc.getElementById('showUserPicker1');
			var userResult1 = doc.getElementById('userResult1');
			var why = doc.getElementById('why');
			showUserPickerButton1.addEventListener('tap', function(event) {
				userPicker1.show(function(items) {
					userResult1.innerHTML =items[0].text;
					why.value=items[0].value
					//返回 false 可以阻止选择框的关闭
					//return false;
				});
			}, false);
		});
	})(mui, document);	
	(function($, doc) {
		$.init();
		$.ready(function() {
			//普通示例
			var userPicker1 = new $.PopPicker();
			userPicker1.setData([{
				text: '退货',value:0 
			},{
				text: '换货',value:1 
			}]);
			var showUserPickerButton1 = doc.getElementById('showUserPicker2');
			var userResult1 = doc.getElementById('userResult2');
			var why = doc.getElementById('type');
			showUserPickerButton1.addEventListener('tap', function(event) {
				userPicker1.show(function(items) {
					userResult1.innerHTML =items[0].text;
					why.value=items[0].value
					//返回 false 可以阻止选择框的关闭
					//return false;
				});
			}, false);
		});
	})(mui, document);	
	function serialize(form){
		 var form=document.getElementById(form);
		 var arr={};
			for (var i = 0; i < form.elements.length; i++) {
				    var feled=form.elements[i];
				    switch(feled.type) {
				    case undefined:
				    case 'button':
				    case 'file':
				    case 'reset':
				    case 'submit':
				    break;
				    case 'checkbox':
				    case 'radio':
				    if (!feled.checked) {
				    	break;
				    }
				    default:
				    if (arr[feled.name]) {
					    arr[feled.name]=arr[feled.name]+','+feled.value;
				    }else{
					    arr[feled.name]=feled.value;
				    } 
			    }
		 	}
		 	return arr
		 }

	var url=location.search
	var code=url.split("=")[1];
	var btn=document.getElementById("btn")
	btn.addEventListener('tap', function() {
		var why=document.getElementById("why").value;
		if(!why){
			mui.toast("请选择退款原因");
			return false;
		}
		var that=this
		that.disabled=true
		var btnArray = ['否', '是'];
		mui.confirm('确定申请退货吗', '提示', btnArray, function(e) {
			if (e.index) {
				var form=serialize('form')
				mui.ajax(window.location.href,{
					type:'post',
					data:form,
					dataType:'json',
					timeout:10000,
					success: function(data){
    				if (data==1) {
						mui.alert("提交成功，请等待卖家处理","",function () {
							window.location.href="/mobile/my/order?status=6"
						});
    				}else if(data==0){
    					mui.toast("网络慢，请重试");
    				}else{
    					mui.alert("该订单已经申请过退款");
    				}
    				that.disabled=false
    			},
				error: function(xhr, type){
					mui.toast("网络慢，请重试");
					that.disabled=false
				// 即使加载出错，也得重置
				}
				});
			}else{
				that.disabled=false
			}
		})
	});
</script>
